package servlet;

import javax.servlet.*;
import javax.servlet.annotation.*;
import java.io.IOException;
// zpl
@WebFilter(filterName = "EncodingFilter", value = "*.s")
public class EncodingFilter implements Filter {
    public void init(FilterConfig config) throws ServletException {
    }

    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        // 默认设置资源返回的结果类型时 json
        response.setContentType("application/json;charset=utf-8");
        chain.doFilter(request, response);
        System.out.println("过滤后");
    }
}
